package com.tjbank.cssys.web.controller;

import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CkLog;
import com.tjbank.cssys.web.service.CkLogService;
import com.tjbank.cssys.web.service.CkOrderLoanPeopleDivisionService;
import com.tjbank.cssys.web.util.CommonResult;
import com.tjbank.cssys.web.util.GetUserCodeFromToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

@Api(tags = "CkOrderLoanPeopleDivisionController",description = "人工分案历史查询",basePath = "/people/division")
@RestController
@RequestMapping("/people/division")
public class CkOrderLoanPeopleDivisionController {

    private static final Logger logger = LoggerFactory.getLogger(CkOrderLoanOutsourcingController.class);


    @Autowired
    private CkOrderLoanPeopleDivisionService ckOrderLoanPeopleDivisionService;
    @Autowired
    private CkLogService ckLogService;

    @ApiOperation("人工分案数据  列表")
    @PostMapping("/list")
    public CommonResult selectList(@RequestBody Map<String,String> params , HttpServletRequest request){
        PageInfo pageData = ckOrderLoanPeopleDivisionService.selectList(params,request);

        String userCode = null;
        try {
            userCode = GetUserCodeFromToken.getUserCode(request);
        } catch (Exception e) {
            logger.error("获取当前登录人信息失败"+e.getMessage());
        }
        CkLog ckLog = new CkLog();
        ckLog.setLogId(UUID.randomUUID().toString());
        ckLog.setLogName(UUID.randomUUID().toString());
        Date date = new Date();
        ckLog.setTimes(new Date(date.getTime()));
        ckLog.setUserId(userCode);
        ckLog.setParams("");
        ckLog.setOperationType("获取人工分案数据列表");

        if(ckOrderLoanPeopleDivisionService!=null){
            ckLog.setResult("success:200");
            ckLogService.addInsert(ckLog);
            return CommonResult.success(pageData,"查询成功！");
        }else{
            ckLog.setResult("error:500");
            ckLogService.addInsert(ckLog);
            return  CommonResult.failed("操作有误");
        }

    }

}
